#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<unordered_map>
using namespace std;

class Solution {
public:
    int waysToStep(int n) {
        if (n == 1) return 1;
        if (n == 2) return 2;
        if (n == 3) return 4;
        const int mod = 1e9 + 7;
        int a = 1, b = 2, c = 4, d;
        for (int i = 4; i <= n; ++i)
        {
            d = ((a + b) % mod + c) % mod;
            a = b;
            b = c;
            c = d;
        }
        return d;
    }

    bool isUnique(string astr) {
        int check = 0;
        for (const char& ch : astr)
        {
            int i = ch - 'a';
            if ((check >> i) & 1) return false;
            check |= (1 << i);
        }
        return true;
    }

    int findShortestSubArray(vector<int>& nums) {
        unordered_map<int, vector<int>> hash;
        int n = nums.size();
        for (int i = 0; i < n; ++i)
        {
            ++hash[nums[i]][0];
            if (hash.count(nums[i]))
            {
                ++hash[nums[i]][0];
                hash[nums[i]][2] = i;
            }
            else hash[nums[i]] = { 1,i,i };
        }
        int maxNum = 0, minLen = 0;
        for (auto kv : hash)
        {
            if (maxNum < kv.second[0])
            {
                maxNum = kv.second[0];
                minLen = kv.second[2] - kv.second[1] + 1;
            }
            else if (maxNum == kv.second[0])
            {
                if (minLen > kv.second[2] - kv.second[1] + 1)
                    minLen = kv.second[2] - kv.second[1] + 1;
            }
        }
        return minLen;
    }
};